package org.meichao.demo.service.factory;

import org.meichao.demo.service.strategy.BadgeStrategy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class BadgeFactory {

    /**
     * 所有实现类自动注入
     */
    @Resource
    List<BadgeStrategy> badgeStrategies;

    /**
     * 根据入参badgeType来匹配使用哪一个实现类
     * @param badgeType
     * @return
     */
    public BadgeStrategy getBadgeStrategy(String badgeType){
        for (BadgeStrategy badgeStrategy : badgeStrategies) {
            if (badgeStrategy.checkOut(badgeType)) {
                return badgeStrategy;
            }
        }
        return null;
    }

    /**
     * 获取所有实现类
     * @return
     */
    public List<BadgeStrategy> getAllStrategy(){
        return badgeStrategies;
    }

}
